//
//  UIView+HDMsgHeaderView.m
//  app
//
//  Created by D on 15/6/24.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HDMsgHeaderView.h"

static CGFloat kMargin = 24.0f;
static CGFloat kImageWight = 144.0f;
static CGFloat kNameWight = 380.0f;
static CGFloat kNameHight = 48.0f;
static CGFloat kPriceWight = 150.0f;
static CGFloat kPriceHight = 30.0f;
static CGFloat kSendWight = 220.0f;
static CGFloat kSendHight = 60.0f;

@implementation HDMsgHeaderView

-(id)initWithDic:(NSDictionary *)dic 
{
    if (self = [super init]) {
        
        if ([[dic objectForKey:@"isShop"]integerValue] == 1) {
            
            self.frame = CGRectMake(0, 0, UBO_WINDOW.width, 95);
            self.backgroundColor = [UIColor clearColor];
            
            UIView * mianView = [[UIView alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin/2 fy:0 oy:2],[self.ubo  ow:UBO_WINDOW.width-kMargin oh:95])];
            mianView.layer.masksToBounds = YES;
            mianView.layer.cornerRadius = UF(6);
            mianView.layer.borderColor =[UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0].CGColor;
            mianView.layer.borderWidth = 0.5;
            mianView.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0];
            [self addSubview:mianView];
            
            
            self.shopImage = [[UIImageView alloc]initWithFrame:CGRectOf([mianView.ufo fx:0 ox:kMargin/8 fy:UB_1_2 oy:-kImageWight/4], [self.ubo ow:kImageWight/2 oh:kImageWight/2])];
            self.shopImage.layer.borderColor = [UIColor colorWithRed:221.0/255.0 green:221.0/255.0 blue:221.0/255.0 alpha:1.0].CGColor;
            self.shopImage.layer.borderWidth = 0.3;
            self.shopImage.layer.masksToBounds = YES;
            self.shopImage.layer.cornerRadius = UF(6);
            //        [self.shopImage setImage:[UIImage imageNamed:[dic objectForKey:@"image"]]];
            [self.shopImage sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"image"]]];
            [mianView addSubview:self.shopImage];
            
            
            DLog(@"w = %f",mianView.frame.size.width);
            CGFloat shopNameW = mianView.frame.size.width - (kMargin/8+kMargin+kImageWight/2);
            self.shopName = [[UILabel alloc]initWithFrame:CGRectOf([self.shopImage.ufo fx:1 ox:kMargin/2 fy:0 oy:-kMargin/4], [self.ubo ow:shopNameW oh:kNameHight])];
            self.shopName.lineBreakMode = NSLineBreakByCharWrapping;
            self.shopName.numberOfLines = 2;
            [self.shopName setFont:JKAppGlobleFontSmallTagText];
            self.shopName.text = [dic objectForKey:@"name"];
            self.shopName.textColor = [UIColor blackColor];
            //        self.shopName.backgroundColor = [UIColor redColor];
            [mianView addSubview:self.shopName];
            
            UILabel * kangXiHui = [[UILabel alloc]initWithFrame:CGRectOf([self.shopImage.ufo fx:1 ox:kMargin/4 fy:UB_2_3 oy:8], [self.ubo ow:kPriceWight/10 oh:kPriceHight/2])];
            kangXiHui.textColor = [UIColor blackColor];
            [kangXiHui setTextAlignment:NSTextAlignmentLeft];
            [kangXiHui setFont:JKAppGlobleFontContentText];
            kangXiHui.text = @"￥";
            [mianView addSubview:kangXiHui];
            
            
            self.shopPrice = [[UILabel alloc]initWithFrame:CGRectOf([kangXiHui.ufo fx:1  fy:0 oy:-2], [self.ubo ow:kPriceWight/2 oh:kPriceHight/2])];
            [self.shopPrice setFont:JKAppGlobleFontTitleBar];
            self.shopPrice.textColor = [UIColor blackColor];
            self.shopPrice.text = [dic objectForKey:@"price"];
            //        self.shopPrice.backgroundColor = [UIColor yellowColor];
            [mianView addSubview:self.shopPrice];
            
            
            CGFloat sendInterLinkW = mianView.frame.size.width - (kPriceWight/2+kPriceWight/10+kMargin/4+kMargin/8+kImageWight/2+kMargin*2);
            self.sendInterLink = [[UIButton alloc]initWithFrame:CGRectOf([self.shopPrice.ufo fx:1 ox:kMargin fy:UB_1_2 oy:-kSendHight/4], [self.ubo ow:sendInterLinkW oh:kSendHight/2])];
            self.sendInterLink.layer.masksToBounds = YES;
            self.sendInterLink.layer.cornerRadius = UF(10);
            //        self.sendInterLink.layer.borderColor = [UIColor colorWithRed:136.0/255.0 green:136.0/255.0 blue:136.0/255.0 alpha:1.0].CGColor;
            //        self.sendInterLink.layer.borderWidth = 1;
            //        self.sendInterLink.backgroundColor = [UIColor redColor];
            [self.sendInterLink setTitle:@"发送链接" forState:UIControlStateNormal];
            self.sendInterLink.tag = 1;
            self.sendInterLink.titleLabel.font = JKAppGlobleFontSmallTagText;
            self.sendInterLink.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
            [self.sendInterLink setTitleColor:[UIColor colorWithRed:136.0/255.0 green:136.0/255.0 blue:136.0/255.0 alpha:1.0] forState:UIControlStateNormal];
            [self.sendInterLink addTarget:self action:@selector(sendShopLink:) forControlEvents:UIControlEventTouchUpInside];
//            [self addSubview:self.sendInterLink];
            
        }else
        {
            self.frame = CGRectMake(0, 0, UBO_WINDOW.width, 95);
            self.backgroundColor = [UIColor clearColor];
            
            UIView * mianView = [[UIView alloc]initWithFrame:CGRectOf([self.ubo fx:0 ox:kMargin/2 fy:0 oy:2],[self.ubo  ow:UBO_WINDOW.width-kMargin oh:60])];
            mianView.layer.masksToBounds = YES;
            mianView.layer.cornerRadius = UF(6);
            mianView.layer.borderColor =[UIColor colorWithRed:220.0/255.0 green:220.0/255.0 blue:220.0/255.0 alpha:1.0].CGColor;
            mianView.layer.borderWidth = 0.5;
            mianView.backgroundColor = [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0];
            [self addSubview:mianView];
            
            
            UILabel * money = [[UILabel alloc]initWithFrame:CGRectOf([mianView.ufo fx:0 ox:kMargin/2 fy:0 oy:kMargin/2], [self.ubo ow:46 oh:16])];
            money.text = @"金额：";
            [money setFont:JKAppGlobleFontContentText];
            [self addSubview:money];
            
            self.reserve_price = [[UILabel alloc]initWithFrame:CGRectOf([money.ufo fx:1 fy:1 oy:-16], [self.ubo ow:100 oh:16 ])];
            self.reserve_price.text = [NSString stringWithFormat:@"￥%@",[dic objectForKey:@"reserve_price"]];
            [self.reserve_price setTextColor:[UIColor colorWithRed:225.0/255.0 green:127.0/255.0 blue:23.0/255.0 alpha:1.0]];
            [self.reserve_price setFont:JKAppGlobleFontTitleBar];
            [self addSubview:self.reserve_price];
            
            
            self.reserve_number = [[UILabel alloc]initWithFrame:CGRectOf([money.ufo fx:0 fy:1 uy:kMargin/2], [self.ubo ow:200 oh:16])];
            self.reserve_number.text = [NSString stringWithFormat:@"订单号:%@",[dic objectForKey:@"reserve_number"]];
            [self.reserve_number setFont:JKAppGlobleFontMinTagText];
            [self addSubview:self.reserve_number];
            
            
            UILabel * doneLab = [[UILabel alloc]initWithFrame:CGRectOf([mianView.ufo fx:1 ox:-kMargin/2-76 fy:UB_1_2 oy:-13], [self.ubo ow:76 oh:26])];
            doneLab.text = [dic objectForKey:@"reserve_status"];
            [doneLab setTextAlignment:NSTextAlignmentCenter];
            [doneLab setTextColor:[UIColor colorWithRed:136.0/255.0 green:136.0/255.0 blue:136.0/255.0 alpha:1.0]];
            doneLab.layer.masksToBounds = YES;
            doneLab.layer.cornerRadius = UF(10);
            doneLab.layer.borderColor = [UIColor colorWithRed:136.0/255.0 green:136.0/255.0 blue:136.0/255.0 alpha:1.0].CGColor;
            doneLab.layer.borderWidth = 1;
            [doneLab setFont:JKAppGlobleFontMenu];
            [self addSubview:doneLab];
            

        }
        
        
        
        
    }
    return self;
}
-(void)sendShopLink:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(sendShopLinkToServer:)]) {
        [self.delegate sendShopLinkToServer:sender];
    }
}


@end
